<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // promise 解决问题是回调函数
      // promise 三个状态 pending fuldilled failed
      // pending 等待的状态
      // fulfilled promise的resolve方法来确定的
      // failed promise的reject方法来确定
      // promise的状态一旦饱满 就不可改变

      // resolve() 并且可以传一个值 resolve(123)
      function fn() {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            resolve("错误");
          }, 2000);
        });
      }
      fn()
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(res);
        });
    </script>
  </body>
</html>
